﻿import mx.utils.Delegate;

import com.mixmedia.mx.AbstractMovieClipEventDispatcher;
import com.mixmedia.mx.events.EventButton;
import com.mixmedia.mx.IEventDispatcher;
/**
 * @author Colin
 */
class com.fangmeiti.control.ButtonClip extends AbstractMovieClipEventDispatcher implements IEventDispatcher{
	private var hitArea:Button;
	private var mcDisable : MovieClip;

	public var isEnable : Boolean;
	
	public function ButtonClip(){
		var btn = (hitArea==null)?this:hitArea;
		btn.onPress = Delegate.create(this,press);
		btn.onRelease = Delegate.create(this,release);
		btn.onRollOver = Delegate.create(this,over);
		btn.onRollOut = Delegate.create(this,out);
		
		mcDisable._visible = false;
	}
	
	private function press(){
		if(isEnable==false)return;
		dispatchEvent(new EventButton(this,EventButton.EVENTPRESS));
	}
	
	private function release(){
		if(isEnable==false)return;
		dispatchEvent(new EventButton(this,EventButton.EVENTRELEASE));
	}

	private function over(){
		if(isEnable==false)return;
		dispatchEvent(new EventButton(this,EventButton.EVENTROLLOVER));
	}

	private function out(){
		if(isEnable==false)return;
		dispatchEvent(new EventButton(this,EventButton.EVENTROLLOUT));
	}

	public function setEnable(bln : Boolean) : Void {
		isEnable = bln;
		_visible = bln;
	}
}